package cn.keniykey.mc.viewlibrary.view.api;

import javax.annotation.Nullable;

import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;

import cn.keniykey.mc.viewlibrary.container.api.ContainerClickReport;
import cn.keniykey.mc.viewlibrary.container.api.EClickType;

public class ViewClickReport {
	protected final ContainerClickReport report;
	
	protected ViewClickReport(ContainerClickReport report1) {
		this.report = report1;
	}
	
	public ClickType getClickType() {
		return coverClickType(this.report.getEClickType());
	}
	public boolean isLeftClick() {
		return this.report.getEClickType().isLeftClick();
	}
	public boolean isRightClick() {
		return this.report.getEClickType().isRightClick();
	}
	public boolean isShiftClick() {
		return this.report.getEClickType().isShiftClick();
	}
	public int getClickRawSlot() {
		return this.report.getClickSlot();
	}
	public boolean isClickContainer() {
		return this.report.isClickContainer();
	}
	public boolean isClickPlayerBackpack() {
		return this.report.isClickPlayerBackpack();
	}
	@Nullable
	public ItemStack getCursorItemStack() {
		return this.report.getCursorItemStack();
	}
	public void setCursorLocationItemStack(@Nullable ItemStack item) {
		ContainerClickReport.setItemStackWithSlot(this.report.getPlayer(), this.report.getContainer(), this.report.getClickSlot(), item);
	}
	
	private static ClickType coverClickType(EClickType type) {
		if(type.isNumberKeyClick()) return ClickType.NUMBER_KEY;
		switch(type) {
		case CONTROL_DROP: return ClickType.CONTROL_DROP;
		case DROP: return ClickType.DROP;
		case LEFT: return ClickType.LEFT;
		case SHIFT_LEFT: return ClickType.SHIFT_LEFT;
		case RIGHT: return ClickType.RIGHT;
		case SHIFT_RIGHT: return ClickType.SHIFT_RIGHT;
		case DOUBLE_CLICK: return ClickType.DOUBLE_CLICK;
		case MIDDLE: return ClickType.MIDDLE;
		case OFFHAND: return ClickType.valueOf("SWAP_OFFHAND");
		case ABROAD_LEFT_EMPTY: //down
		case ABROAD_LEFT_ITEM: return ClickType.WINDOW_BORDER_LEFT;
		case ABROAD_RIGHT_EMPTY: //down
		case ABROAD_RIGHT_ITEM: return ClickType.WINDOW_BORDER_RIGHT;
		default:
		}
		return ClickType.UNKNOWN;
	}
}